package com.wymobilearchitecture.demo.tab

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

import com.example.w_library.utils.DisplayUtil
import com.wy.w_ui.tab.bottom.WTabBottom
import com.wy.w_ui.tab.bottom.WTabBottomInfo
import com.wy.w_ui.tab.bottom.WTabBottomLayout
import com.wy.w_ui.tab.common.IWTabLayout
import com.wymobilearchitecture.R

class TabBottomActivity :AppCompatActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tab_bottom)

        var tabBottomLayout: WTabBottomLayout = findViewById(R.id.tab_bottom)

        tabBottomLayout.setTabAlpha(0.6f)

        var tabList:MutableList<WTabBottomInfo<*>> = ArrayList()

        val home1  = WTabBottomInfo(
            "首页",
            "fonts/iconfont.ttf",
            getString(R.string.if_home_icon),
            getString(R.string.if_home_icon),
            "#ff656667",
            "#ffd44949",
            WTabBottomInfo.TabType.ICON
        )

        val home2  = WTabBottomInfo(
            "首页",
            "fonts/iconfont.ttf",
            getString(R.string.if_recommend),
            getString(R.string.if_recommend),
            "#ff656667",
            "#ffd44949",
            WTabBottomInfo.TabType.ICON
        )

//        val home3  = WTabBottomInfo(
//            "首页",
//            "fonts/iconfont.ttf",
//            getString(R.string.if_chat),
//            getString(R.string.if_chat),
//            "#ff656667",
//            "#ffd44949",
//            WTabBottomInfo.TabType.ICON
//        )

        val bitmap: Bitmap = BitmapFactory.decodeResource(resources,R.mipmap.ic_launcher,null)

        val home3 = WTabBottomInfo<String>(
            "icon",
            bitmap,bitmap
        )


        val home4  = WTabBottomInfo(
            "首页",
            "fonts/iconfont.ttf",
            getString(R.string.if_profile),
            getString(R.string.if_profile),
            "#ff656667",
            "#ffd44949",
            WTabBottomInfo.TabType.ICON
        )

        val home5  = WTabBottomInfo(
            "首页",
            "fonts/iconfont.ttf",
            getString(R.string.if_category),
            getString(R.string.if_category),
            "#ff656667",
            "#ffd44949",
            WTabBottomInfo.TabType.ICON
        )

        tabList.add(home1)
        tabList.add(home2)
        tabList.add(home3)
        tabList.add(home4)
        tabList.add(home5)

        tabBottomLayout.inflateInfo(tabList)

        tabBottomLayout.defaultSelected(home1)

//        tabBottomLayout.addTabSelectChangeListener{
//                _, _, nextInfo -> Toast.makeText(this@TabBottomActivity,nextInfo.name,Toast.LENGTH_SHORT).show()
//        }
//
        tabBottomLayout.addTabSelectChangeListener(object : IWTabLayout.OnTabSelectListener<WTabBottomInfo<*>>{
            override fun onTabSelectChange(
                index: Int,
                prevInfo: WTabBottomInfo<*>?,
                nextInfo: WTabBottomInfo<*>
            ) {
                Toast.makeText(this@TabBottomActivity,nextInfo.name,Toast.LENGTH_SHORT).show()
            }
        })

        val tab3 : WTabBottom = tabBottomLayout.findTab(home3)

        tab3?.apply { restHeight(DisplayUtil.dp2Px(context,66)) }

    }
}